From: kaf24@firebug.cl.cam.ac.uk Date: Tue, 4 Oct 2005 14:34:02 +0000 (+0100) Subject: Clean up sched_op() hypercall interface. One particular X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~16763^2~50 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=1872f40d7898764a5bec726ca98c007ee3a8c2b2;p=xen.git Clean up sched_op() hypercall interface. One particular change to watch out for is that the suspend record, on save/restore, is now passed via register %edx not %esi (both i386 and x86/64). Signed-off-by: Keir Fraser --- diff --git a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c index ee5d05ab7b..db8cbed8cd 100644 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c @@ -106,7 +106,8 @@ void xen_idle(void) local_irq_enable(); } else { stop_hz_timer(); - HYPERVISOR_block(); /* implicit local_irq_enable() */ + /* Blocking includes an implicit local_irq_enable(). */ + HYPERVISOR_sched_op(SCHEDOP_block, 0); start_hz_timer(); } } @@ -122,7 +123,7 @@ static inline void play_dead(void) { /* Death loop */ while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE) - HYPERVISOR_yield(); + HYPERVISOR_sched_op(SCHEDOP_yield, 0); __flush_tlb_all(); /* diff --git a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c index 84b769a14b..17788f3862 100644 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c @@ -1784,7 +1784,7 @@ void __init setup_arch(char **cmdline_p) static int xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr) { - HYPERVISOR_crash(); + HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash); /* we're never actually going to get here... */ return NOTIFY_DONE; } diff --git a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c index 59fc5f0b78..6d7c4a634f 100644 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c @@ -26,7 +26,7 @@ void machine_restart(char * __unused) /* We really want to get pending console data out before we die. */ extern void xencons_force_flush(void); xencons_force_flush(); - HYPERVISOR_reboot(); + HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_reboot); } void machine_halt(void) @@ -39,7 +39,7 @@ void machine_power_off(void) /* We really want to get pending console data out before we die. */ extern void xencons_force_flush(void); xencons_force_flush(); - HYPERVISOR_shutdown(); + HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_poweroff); } int reboot_thru_bios = 0; /* for dmi_scan.c */ diff --git a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c index e234671dbd..ea4b1b60b7 100644 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c @@ -96,7 +96,8 @@ void xen_idle(void) local_irq_enable(); } else { stop_hz_timer(); - HYPERVISOR_block(); /* implicit local_irq_enable() */ + /* Blocking includes an implicit local_irq_enable(). */ + HYPERVISOR_sched_op(SCHEDOP_block, 0); start_hz_timer(); } } @@ -114,7 +115,7 @@ static inline void play_dead(void) * it "work" for testing purposes. */ /* Death loop */ while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE) - HYPERVISOR_yield(); + HYPERVISOR_sched_op(SCHEDOP_yield, 0); local_irq_disable(); __flush_tlb_all(); diff --git a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h index 4509c065b3..6fc4203116 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h @@ -31,6 +31,7 @@ #define __HYPERCALL_H__ #include +#include #define _hypercall0(type, name) \ ({ \ @@ -160,41 +161,10 @@ HYPERVISOR_fpu_taskswitch( } static inline int -HYPERVISOR_yield( - void) +HYPERVISOR_sched_op( + int cmd, unsigned long arg) { - return _hypercall2(int, sched_op, SCHEDOP_yield, 0); -} - -static inline int -HYPERVISOR_block( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_block, 0); -} - -static inline int -HYPERVISOR_shutdown( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_shutdown | - (SHUTDOWN_poweroff << SCHEDOP_reasonshift), 0); -} - -static inline int -HYPERVISOR_reboot( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_shutdown | - (SHUTDOWN_reboot << SCHEDOP_reasonshift), 0); -} - -static inline int -HYPERVISOR_crash( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_shutdown | - (SHUTDOWN_crash << SCHEDOP_reasonshift), 0); + return _hypercall2(int, sched_op, cmd, arg); } static inline long @@ -326,19 +296,8 @@ static inline int HYPERVISOR_suspend( unsigned long srec) { - int ret; - unsigned long ign1, ign2; - - /* On suspend, control software expects a suspend record in %esi. */ - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign1), "=S" (ign2) - : "0" (__HYPERVISOR_sched_op), - "1" (SCHEDOP_shutdown | (SHUTDOWN_suspend << - SCHEDOP_reasonshift)), - "2" (srec) : "memory", "ecx"); - - return ret; + return _hypercall3(int, sched_op, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); } #endif /* __HYPERCALL_H__ */ diff --git a/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h b/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h index f2b785143b..fcfd4a5890 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-ia64/hypercall.h @@ -29,7 +29,9 @@ #ifndef __HYPERCALL_H__ #define __HYPERCALL_H__ + #include +#include /* FIXME: temp place to hold these page related macros */ #include @@ -184,77 +186,9 @@ HYPERVISOR_fpu_taskswitch( } static inline int -HYPERVISOR_yield( - void) +HYPERVISOR_sched_op( + int cmd, unsigned long arg) { -#if 0 - int ret; - unsigned long ign; - - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign) - : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield) - : "memory" ); - - return ret; -#endif - return 1; -} - -static inline int -HYPERVISOR_block( - void) -{ -#if 0 - int ret; - unsigned long ign1; - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign1) - : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block) - : "memory" ); - - return ret; -#endif - return 1; -} - -static inline int -HYPERVISOR_shutdown( - void) -{ -#if 0 - int ret; - unsigned long ign1; - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign1) - : "0" (__HYPERVISOR_sched_op), - "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift)) - : "memory" ); - - return ret; -#endif - return 1; -} - -static inline int -HYPERVISOR_reboot( - void) -{ -#if 0 - int ret; - unsigned long ign1; - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign1) - : "0" (__HYPERVISOR_sched_op), - "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift)) - : "memory" ); - - return ret; -#endif return 1; } @@ -262,39 +196,6 @@ static inline int HYPERVISOR_suspend( unsigned long srec) { -#if 0 - int ret; - unsigned long ign1, ign2; - - /* NB. On suspend, control software expects a suspend record in %esi. */ - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign1), "=S" (ign2) - : "0" (__HYPERVISOR_sched_op), - "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), - "S" (srec) : "memory"); - - return ret; -#endif - return 1; -} - -static inline int -HYPERVISOR_crash( - void) -{ -#if 0 - int ret; - unsigned long ign1; - __asm__ __volatile__ ( - TRAP_INSTR - : "=a" (ret), "=b" (ign1) - : "0" (__HYPERVISOR_sched_op), - "1" (SCHEDOP_shutdown | (SHUTDOWN_crash << SCHEDOP_reasonshift)) - : "memory" ); - - return ret; -#endif return 1; } diff --git a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h index 3421a300e5..bb338772d0 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h @@ -35,6 +35,7 @@ #define __HYPERCALL_H__ #include +#include #define __syscall_clobber "r11","rcx","memory" @@ -165,33 +166,10 @@ HYPERVISOR_fpu_taskswitch( } static inline int -HYPERVISOR_yield( - void) +HYPERVISOR_sched_op( + int cmd, unsigned long arg) { - return _hypercall2(int, sched_op, SCHEDOP_yield, 0); -} - -static inline int -HYPERVISOR_block( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_block, 0); -} - -static inline int -HYPERVISOR_shutdown( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_shutdown | - (SHUTDOWN_poweroff << SCHEDOP_reasonshift), 0); -} - -static inline int -HYPERVISOR_reboot( - void) -{ - return _hypercall2(int, sched_op, SCHEDOP_shutdown | - (SHUTDOWN_reboot << SCHEDOP_reasonshift), 0); + return _hypercall2(int, sched_op, cmd, arg); } static inline long @@ -325,8 +303,8 @@ static inline int HYPERVISOR_suspend( unsigned long srec) { - return _hypercall2(int, sched_op, SCHEDOP_shutdown | - (SHUTDOWN_suspend << SCHEDOP_reasonshift), srec); + return _hypercall3(int, sched_op, SCHEDOP_shutdown, + SHUTDOWN_suspend, srec); } #endif /* __HYPERCALL_H__ */ diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c index 7d4e43eba3..1d8cfacf0f 100644 --- a/tools/libxc/xc_linux_restore.c +++ b/tools/libxc/xc_linux_restore.c @@ -500,13 +500,13 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns, } /* Uncanonicalise the suspend-record frame number and poke resume rec. */ - pfn = ctxt.user_regs.esi; + pfn = ctxt.user_regs.edx; if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) ) { ERR("Suspend record frame number is bad"); goto out; } - ctxt.user_regs.esi = mfn = pfn_to_mfn_table[pfn]; + ctxt.user_regs.edx = mfn = pfn_to_mfn_table[pfn]; start_info = xc_map_foreign_range( xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn); start_info->nr_pages = nr_pfns; diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index 39ea57a5e6..4720e4076a 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -978,9 +978,9 @@ int xc_linux_save(int xc_handle, int io_fd, u32 dom, u32 max_iters, goto out; } - DPRINTF("SUSPEND shinfo %08lx eip %08u esi %08u\n", + DPRINTF("SUSPEND shinfo %08lx eip %08u edx %08u\n", info.shared_info_frame, - ctxt.user_regs.eip, ctxt.user_regs.esi); + ctxt.user_regs.eip, ctxt.user_regs.edx); } if ( xc_shadow_control( xc_handle, dom, @@ -1048,7 +1048,7 @@ int xc_linux_save(int xc_handle, int io_fd, u32 dom, u32 max_iters, } /* Canonicalise the suspend-record frame number. */ - if ( !translate_mfn_to_pfn(&ctxt.user_regs.esi) ) + if ( !translate_mfn_to_pfn(&ctxt.user_regs.edx) ) { ERR("Suspend record is not in range of pseudophys map"); goto out; diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 5094e17ba7..2fe9bee750 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -25,6 +25,7 @@ typedef int64_t s64; #include #include #include +#include #include #include diff --git a/tools/xenstat/libxenstat/src/xen-interface.h b/tools/xenstat/libxenstat/src/xen-interface.h index 317e08581c..8d8c403147 100644 --- a/tools/xenstat/libxenstat/src/xen-interface.h +++ b/tools/xenstat/libxenstat/src/xen-interface.h @@ -28,6 +28,7 @@ typedef uint64_t u64; #include #include +#include #include /* Opaque handles */ diff --git a/xen/arch/x86/vmx.c b/xen/arch/x86/vmx.c index c4954ee994..a72aca4109 100644 --- a/xen/arch/x86/vmx.c +++ b/xen/arch/x86/vmx.c @@ -41,7 +41,7 @@ #if CONFIG_PAGING_LEVELS >= 3 #include #endif - +#include #include int hvm_enabled; diff --git a/xen/common/domain.c b/xen/common/domain.c index 890a61f205..99e4e354ee 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -18,6 +18,7 @@ #include #include #include +#include #include /* Both these structures are protected by the domlist_lock. */ diff --git a/xen/common/schedule.c b/xen/common/schedule.c index fe6de36988..c7bafd2d71 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -36,6 +36,7 @@ #include #include #include +#include #include extern void arch_getdomaininfo_ctxt(struct vcpu *, @@ -270,11 +271,11 @@ static long do_yield(void) return 0; } -long do_sched_op(unsigned long op, unsigned long arg) +long do_sched_op(int cmd, unsigned long arg) { long ret = 0; - switch ( op & SCHEDOP_cmdmask ) + switch ( cmd ) { case SCHEDOP_yield: { @@ -291,9 +292,8 @@ long do_sched_op(unsigned long op, unsigned long arg) case SCHEDOP_shutdown: { TRACE_3D(TRC_SCHED_SHUTDOWN, - current->domain->domain_id, current->vcpu_id, - (op >> SCHEDOP_reasonshift)); - domain_shutdown((u8)(op >> SCHEDOP_reasonshift)); + current->domain->domain_id, current->vcpu_id, arg); + domain_shutdown((u8)arg); break; } diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index 83fda53e1e..9b8accfa4d 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -19,7 +19,7 @@ * This makes sure that old versions of dom0 tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define DOM0_INTERFACE_VERSION 0xAAAA1010 +#define DOM0_INTERFACE_VERSION 0xAAAA1011 /************************************************************************/ diff --git a/xen/include/public/sched.h b/xen/include/public/sched.h new file mode 100644 index 0000000000..5659e57026 --- /dev/null +++ b/xen/include/public/sched.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * sched.h + * + * Scheduler state interactions + * + * Copyright (c) 2005, Keir Fraser + */ + +#ifndef __XEN_PUBLIC_SCHED_H__ +#define __XEN_PUBLIC_SCHED_H__ + +/* + * Prototype for this hypercall is: + * int sched_op(int cmd, unsigned long arg) + * @cmd == SCHEDOP_??? (scheduler operation). + * @arg == Operation-specific extra argument(s). + */ + +/* + * Voluntarily yield the CPU. + * @arg == 0. + */ +#define SCHEDOP_yield 0 + +/* + * Block execution of this VCPU until an event is received for processing. + * If called with event upcalls masked, this operation will atomically + * reenable event delivery and check for pending events before blocking the + * VCPU. This avoids a "wakeup waiting" race. + * @arg == 0. + */ +#define SCHEDOP_block 1 + +/* + * Halt execution of this domain (all VCPUs) and notify the system controller. + * @arg == SHUTDOWN_??? (reason for shutdown). + */ +#define SCHEDOP_shutdown 2 + +/* + * Reason codes for SCHEDOP_shutdown. These may be interpreted by controller + * software to determine the appropriate action. For the most part, Xen does + * not care about the shutdown code. + */ +#define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */ +#define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */ +#define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */ +#define SHUTDOWN_crash 3 /* Tell controller we've crashed. */ + +#endif /* __XEN_PUBLIC_SCHED_H__ */ diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index 4775299773..8d85d6663c 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -195,25 +195,6 @@ struct mmuext_op { #define UVMF_LOCAL (0UL<<2) /* Flush local TLB. */ #define UVMF_ALL (1UL<<2) /* Flush all TLBs. */ -/* - * Commands to HYPERVISOR_sched_op(). - */ -#define SCHEDOP_yield 0 /* Give up the CPU voluntarily. */ -#define SCHEDOP_block 1 /* Block until an event is received. */ -#define SCHEDOP_shutdown 2 /* Stop executing this domain. */ -#define SCHEDOP_cmdmask 255 /* 8-bit command. */ -#define SCHEDOP_reasonshift 8 /* 8-bit reason code. (SCHEDOP_shutdown) */ - -/* - * Reason codes for SCHEDOP_shutdown. These may be interpreted by control - * software to determine the appropriate action. For the most part, Xen does - * not care about the shutdown code (SHUTDOWN_crash excepted). - */ -#define SHUTDOWN_poweroff 0 /* Domain exited normally. Clean up and kill. */ -#define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. */ -#define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. */ -#define SHUTDOWN_crash 3 /* Tell controller we've crashed. */ - /* * Commands to HYPERVISOR_console_io(). */